package com.buyouchina.web.action.area;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.buyouchina.bean.area.Province;
import com.buyouchina.service.area.ProvinceService;
import com.buyouchina.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class ProvinceAction extends BaseAction implements ModelDriven<Province> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Province province = new Province();
	@Resource(name = "provinceServiceBean")
	ProvinceService provinceService;

	private List<Province> provinceList = new ArrayList<Province>();
	private List<Province> cityList = new ArrayList<Province>();
	private List<Province> regionList = new ArrayList<Province>();
	private String url;
	private String loadmethod;
	private String inputname;

	public String getProvince() {
		String sql = "select p from Province p where p.cityid is null and p.provinceid is null";
		provinceList = provinceService.list(sql);
		url = "/WEB-INF/page/area/select.jsp";
		loadmethod = "loadCity(this)";
		inputname = "province.provinceid";
		return SUCCESS;
	}

	public String getCity() {
		String sql = "select p from Province p where p.provinceid="
				+ province.getProvinceid() + "";
		cityList = provinceService.list(sql);
		url = "/WEB-INF/page/area/cityselect.jsp";
		loadmethod = "loadRegion(this)";
		inputname = "province.cityid";
		return SUCCESS;
	}

	public String getRegion() {
		String sql = "select p from Province p where p.cityid="
				+ province.getCityid() + "";
		regionList = provinceService.list(sql);
		url = "/WEB-INF/page/area/regionselect.jsp";
		inputname = "province.regionid";
		return SUCCESS;
	}

	public ProvinceService getProvinceService() {
		return provinceService;
	}

	public void setProvinceService(ProvinceService provinceService) {
		this.provinceService = provinceService;
	}

	public void setProvince(Province province) {
		this.province = province;
	}

	public Province getModel() {
		// TODO Auto-generated method stub
		return province;
	}

	public List<Province> getProvinceList() {
		return provinceList;
	}

	public void setProvinceList(List<Province> provinceList) {
		this.provinceList = provinceList;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getLoadmethod() {
		return loadmethod;
	}

	public void setLoadmethod(String loadmethod) {
		this.loadmethod = loadmethod;
	}

	public String getInputname() {
		return inputname;
	}

	public void setInputname(String inputname) {
		this.inputname = inputname;
	}

	public List<Province> getCityList() {
		return cityList;
	}

	public void setCityList(List<Province> cityList) {
		this.cityList = cityList;
	}

	public List<Province> getRegionList() {
		return regionList;
	}

	public void setRegionList(List<Province> regionList) {
		this.regionList = regionList;
	}

}
